<template>
	<view>
		<view style="height: 1px;"></view>
		<view @click="go_particulars(item)" class="nav" v-for="(item, index) in list" :key="index">
			<view class="title1">标题：{{ item.title }}</view>
			<view class="title2">时间：{{ item.createTime }}</view>
		</view>
		<uni-load-more v-if="show" :status="loadingType" :contentText="contentText"></uni-load-more>
		<view v-show="topShow" class="uni-top">
			<image class="uni-top-img" src="../../static/imgs/a30.png" mode=""></image>
			<view class="uni-top-title">暂无公告!</view>
		</view>
	</view>
</template>

<script>
import uniLoadMore from '../../components/uni-load-more/uni-load-more.vue';
var timer = null;
export default {
	components: {
		uniLoadMore
	},
	data() {
		return {
			list: [
				// {id:1,name:'biaoti1',time:'2019-12-20 00:00:00'},
				// {id:2,name:'biaoti2',time:'2019-12-20 00:00:00'},
				// {id:3,name:'biaoti3',time:'2019-12-20 00:00:00'},
			],
			show: false,
			loadingType: 'more',
			// loadingType: "noMore",
			// loadingType: "loading",
			contentText: {
				contentdown: '上拉显示更多',
				contentrefresh: '正在加载...',
				contentnomore: '没有更多数据了'
			},
			score: 0,
			page: 1,
			topShow:false
		};
	},
	onReachBottom: function() {
		//触底的时候请求数据，即为上拉加载更多
		//为了更加清楚的看到效果，添加了定时器
		var that = this;
		if (timer != null) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			that.my_detail();
		}, 500);
	},
	onShow() {},
	methods: {
		my_detail() {
			//公告列表
			uni.showLoading({
				mask:false
			})
			uni.request({
				url: '/app/wechatApi/wechatOrder/getNoticeList',
				method: 'GET',
				data: {
					openid: uni.getStorageSync('openid'),
					pageIndex: this.page,
					pageSize: 10
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					uni.hideLoading()
					if (res.data.code === 200) {
						// console.log(res.data.data.records)
						var listDate = res.data.data.records;
						//concat 连接字符串
						this.list = this.list.concat(listDate);
						if (this.list.length == 0) {
							this.show = false;
							this.topShow = true;
							return;
						}
						this.loadingType = 'more';
						this.score = listDate.score;
						this.page += 1;
						uni.hideNavigationBarLoading(); //关闭加载动画
						if (listDate.length == 0) {
							//没有数据
							this.show = true;
							this.loadingType = 'noMore';
							uni.hideNavigationBarLoading(); //关闭加载动画
							return;
						}
					} else {
						uni.showToast({
							title: '网络错误...',
							icon: 'none'
						});
					}
					uni.hideNavigationBarLoading(); //关闭加载动画
				},
				error: e => {
					uni.hideLoading()
					console.log(e);
				}
			});
		},
		go_particulars(item) {
			//去详情
			uni.navigateTo({
				url: '/pages/particulars/particulars?num=' + JSON.stringify(item)
			});
		}
	},
	mounted() {
		//钩子函数
		this.my_detail();
	}
};
</script>

<style>
.nav {
	background: #ffffff;
	padding: 35upx 30upx;
	border: 1px solid #e0e0e0;
	margin: 25upx;
	border-radius: 10upx;
}
.title1 {
	opacity: 0.8;
	font-size: 34upx;
}
.title2 {
	color: #c4c4c4;
}
/* 空数据展示 */
.uni-top {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: 777;
	text-align: center;
}
.uni-top-img {
	width: 168upx;
	height: 168upx;
	margin-bottom: 25upx;
}

.uni-top-title {
	font-size: 24upx;
	white-space: nowrap;
	color: #999999;
}
</style>
